/**
 *<p>Copyright: Copyright (c) 2012</p> 
 *<p>Company: SCPII</p>
 *<p>Project:scpii-api</p>
 *@author xiezhouyan
 *@Date 2013-3-12 下午2:04:47
 *@version 1.0
 *@description:
 */
package com.scpii.api.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

import org.apache.commons.lang.StringUtils;

public class SmsUtil {
	private static final String SMS_UID = "66692489";

	private static final String SMS_PWD = "qwer1234";

	private static final String SMS_URL = "http://www.jxtsms.com/inter.aspx";

	public static String sendSms(String[] mobile, String content) {
		HttpURLConnection httpConn = null;
		String result = "-20";
		String memo = content.length() < 63 ? content.trim() : content.trim()
				.substring(0, 63);
		StringBuilder sb = null;
		try {
			sb = new StringBuilder();
			sb.append("?smsUid=" + SMS_UID);
			sb.append("&smsPwd=" + SMS_PWD);
			sb.append("&smsNumber=" + StringUtils.join(mobile, ","));
			sb.append("&smsContent=" + URLEncoder.encode(memo, "GBK"));
			URL url = new URL(SMS_URL + sb.toString());

			httpConn = (HttpURLConnection) url.openConnection();
			httpConn.setRequestMethod("GET");
			httpConn.setDoInput(true);
			httpConn.setDoOutput(true);
			httpConn.setConnectTimeout(3000);
			BufferedReader rd = new BufferedReader(new InputStreamReader(
					httpConn.getInputStream()));
			result = rd.readLine();
			rd.close();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (httpConn != null) {
				httpConn.disconnect();
				httpConn = null;
			}
		}
		return result;
	}

}
